#include "networkmessageparser.h"

NetworkMessageParser::NetworkMessageParser() {
}

NetworkMessage NetworkMessageParser::parse(QString message) {
    QDomDocument doc("message");
    doc.setContent(message);
    QDomElement rootElement = doc.documentElement();

    NetworkMessage parsedMessage(rootElement.nodeName());

    //qDebug() << rootElement.nodeName();

    QDomElement firstElement = rootElement.firstChildElement();

    while(!firstElement.isNull()) {
        //qDebug() << firstElement.nodeName() << "->" << firstElement.text();
        QString key = firstElement.nodeName();
        QString value = firstElement.text();
        parsedMessage.setData(key, value);

        firstElement = firstElement.nextSiblingElement();
    }

    return parsedMessage;
}
